package com.rongke.web;

import com.rongke.commons.JsonResp;
import com.rongke.model.SelectSpecif;
import com.rongke.service.SelectSpecifService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @SelectSpecifController
 * @定制商品规格表 Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value="/api/selectSpecif")
@Transactional
public class SelectSpecifController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private SelectSpecifService selectSpecifService;

    /**
     * @添加定制商品规格表 
     * @param selectSpecif
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addSelectSpecif(@RequestBody SelectSpecif selectSpecif){
        log.debug("添加定制商品规格表 ");
        selectSpecifService.insert(selectSpecif);
        return JsonResp.ok(selectSpecif);
    }

    /**
     * @修改定制商品规格表 
     * @param selectSpecif
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updateSelectSpecif(@RequestBody SelectSpecif selectSpecif){
        log.debug("修改定制商品规格表 ");
        selectSpecifService.updateById(selectSpecif);
        return JsonResp.ok(selectSpecif);
    }
    /**
     * @根据id查找定制商品规格表 
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectSelectSpecif(Long id){
        log.debug("查找定制商品规格表 ");
        SelectSpecif selectSpecif = selectSpecifService.selectById(id);
        return JsonResp.ok(selectSpecif);
    }


    /**
     * @查询定制商品所有规格
     * @param sgId
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectSpecifList", method = RequestMethod.POST)
    public JsonResp updateSelectSpecif(Long sgId){
        log.debug("查询定制商品所有规格 ");
        Map specifList=selectSpecifService.selectListBysgId(sgId);
        return JsonResp.ok(specifList);
    }





}
